<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>菜单管理</title>
    <link rel="stylesheet" th:href="@{/themes/default/easyui.css}">
    <link rel="stylesheet" th:href="@{/themes/icon.css}">
    <link rel="stylesheet" th:href="@{/css/style.css}">
</head>
<body>
<table id="tg">
    <thead>
    <tr>
        <th data-options="field:'authId',width:20,align:'center'">菜单编号</th>
        <th data-options="field:'authName',width:100,align:'center'">菜单名称</th>
        <th data-options="field:'iconCls',width:100,formatter:iconFormatter,align:'center'">图标</th>
        <th data-options="field:'authPath',width:100,align:'center'">链接地址</th>
        <th data-options="field:'authDescription',width:200,align:'center'">备注</th>
    </tr>
    </thead>
</table>
<div id="toolbar">
    <a class="easyui-linkbutton" data-options="iconCls:'icon-add'" onclick="openAddDialog()">添加</a>
    <a class="easyui-linkbutton" data-options="iconCls:'icon-edit'" onclick="updateAuth()">修改</a>
    <a class="easyui-linkbutton" data-options="iconCls:'icon-remove'" onclick="deleteAuth()">删除</a>
</div>

<div id="dlg" class="easyui-dialog" data-options="width:600,height:400,modal:true,closed:true,buttons:'#buttons'" style="padding: 20px">
    <form id="fm" method="post">
        <input type="hidden" name="parentId" id="pid">
        <table cellspacing="10">
            <tr>
                <td>菜单名称：</td>
                <td>
                    <input type="text" name="authName">
                </td>
                <td>菜单样式：</td>
                <td>
                    <input type="text" name="iconCls">
                </td>
            </tr>
            <tr>
                <td>菜单路径：</td>
                <td>
                    <input type="text" name="authPath">
                </td>
                <td></td>
                <td></td>
            </tr>
            <tr>
                <td>备注</td>
                <td colspan="3">
                    <textarea name="authDescription" id="" cols="50" rows="10"></textarea>
                </td>
            </tr>
        </table>
    </form>
</div>
<div id="buttons">
    <a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="saveAuth()">保存</a>
    <a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'">取消</a>
</div>
<script th:src="@{/js/jquery.min.js}"></script>
<script th:src="@{/js/jquery.easyui.min.js}"></script>
<script th:src="@{/js/easyui-lang-zh_CN.js}"></script>
<script th:inline="javascript">
 var url=[[@{/}]]
</script>
<script th:inline="none">
$("#tg").treegrid({
    url:url+"auth/list",
    fitColumns:true,
    fit:true,
    idField:'authId',
    treeField:'authName',
    title:'菜单列表',
    toolbar:'#toolbar'
})
    function iconFormatter(value,row,index) {
        return "<span class= '"+row.iconCls+" '>&nbsp;&nbsp;&nbsp;&nbsp;</span>";
    }
    var path=null;
function openAddDialog() {
    var rows=$('#tg').treegrid("getSelections");
    if (rows.length!=1){
        $.messager.alert('系统提示','请选择一个节点');
        return;
    }
    $("#pid").val(rows[0].authId);
    $("#dlg").dialog("open").dialog("setTitle","添加菜单");
    path=url+"auth/saveAuth";
}
function saveAuth() {
    $("#fm").form("submit",{ 
        url:path,
        success:function (result) {
            var json=eval("("+result+")");
            if (json.code==200){
                $.messager.alert('系统提示','操作成功');
                $("#dlg").dialog("close");
                $("#fm").form("clear");
                $("#tg").treegrid("reload");
            } else{
                $.messager.alert('系统提示','json.msg');
            }
        }
    })
}
function updateAuth() {
    var rows=$("#tg").treegrid("getSelections");
    if(rows.length != 1){
        $.messager.alert('系统提示','请选择一个节点');
        return ;
    }
    $("#dlg").dialog("open").dialog("setTitle","修改菜单");
    $("#fm").form("load",rows[0]);
    path=url+"auth/update?authId="+rows[0].authId;
}
function deleteAuth() {
    var rows = $("#tg").treegrid("getSelections");
    if(rows.length != 1){
        $.messager.alert('系统提示','请选择要删除的节点');
        return ;
    }

    $.post(url+"auth/delete","authId="+rows[0].authId,function(result){
        if(result.code == 200){

            $.messager.alert('系统提示',result.msg);
            $("#tg").treegrid("reload");

        }else{
            $.messager.alert('系统提示',result.msg);
        }
    });
}
</script>
</body>
</html>